package com.highcom.dao.impl;

import com.highcom.bean.MenuInfo;
import com.highcom.dao.MenuInfoDao;
import com.highcom.util.DBUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 王卓逸
 * @program TODO
 * @description TODO
 * @create 2019-10-10
 */
public class MenuInfoDaoImpl implements MenuInfoDao {

    @Override
    public List<MenuInfo> selectMenuListByUserId(Integer userId) {
        DBUtil.connect();
        List<MenuInfo> menuInfos = new ArrayList<>();
        ResultSet rs = null;
        try {
            rs = DBUtil.executeQuery("select * from menuinfo where id in (select menuId from usermenu where userId=?)", userId);
            while (rs.next()) {
                MenuInfo menuInfo = new MenuInfo();
                menuInfo.setId(rs.getInt("id"));
                menuInfo.setMenuName(rs.getString("menuName"));
                menuInfo.setTarget(rs.getString("target"));
                menuInfo.setUrl(rs.getString("url"));
                menuInfo.setParentId(rs.getInt("parentId"));
                menuInfo.setIcon(rs.getString("icon"));
                menuInfos.add(menuInfo);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs);
        }
        return menuInfos;
    }
}
